<template>
	<view class="setting-wrap full box relative p-safe bg-primary">
		<view class="setting-list">
			<!-- <view class="setting-item">
				<image class="setting-icon" src="../static/clear.png" mode="aspectFill"></image>
				<view class="setting-label">
					<text>清理缓存</text>
				</view>
				<view class="setting-value">
					<text>11M</text>
				</view>
			</view> -->
			<view class="setting-item" v-for="(item,index) in list" :key="index" @click="toService(item.id)">
				<image class="setting-icon" mode="aspectFill" src="../static/service.png"></image>
				<view class="setting-label">
					<text>{{ item.title }}</text>
				</view>
			</view>
		</view>
		<view class="exit-btn">
			<u-button text="退出登录" @click="logout" />
		</view>
	</view>
</template>

<script>
	import { setData } from '@/utils/tool.js'
	let AGREEMENT_MAP = []
	export default {
		created() {
			this.initData()
		},
		methods: {
			async initData() {
				const resp = await this.$request({
					url: "/index/getAgreement",
					data: {},
				})
				const { code, data, msg } = resp
				if (code !== 1) return this.$toast({ title: msg }, () => uni.navigateBack())
				if (!data || !data.length) return this.$toast({ title: '暂未配置' })
				const result = []
				this.list = data.map(item => {
					const { id, title, agreement } = item
					result.push({ id, content: agreement })
					return { id, title }
				})
				AGREEMENT_MAP = result
			},
			toService(id) {
				const target = AGREEMENT_MAP.find(item => item.id === id)
				if (!target) return
				setData(target.content)
				uni.navigateTo({
					url: '/pages-bundle/service/service'
				})
			},
			logout() {
				uni.showModal({
					title: '提示',
					content: '您确定退出重新登录吗?',
					success: async ev => {
						if (ev.cancel) return
						const flag = await this.$store.dispatch('logout')
						if (!flag) return
						this.$toast({ title: '退出成功' }, () => {
							uni.reLaunch({
								url: '/pages/login/login'
							})
						})
					}
				})
			},
		},
		data() {
			return {
				list: [],
			}
		}
	}
</script>

<style lang="scss" scoped>
	.setting-wrap {
		.exit-btn {
			position: absolute;
			left: 0;
			right: 0;
			padding: 0 32rpx;
			box-sizing: border-box;
			bottom: calc(env(safe-area-inset-bottom) + 112rpx);

			::v-deep button {
				height: 80rpx;
				background: linear-gradient(135deg, #8BDCFF 0%, #E4FF68 100%);
				border-radius: 8rpx 8rpx 8rpx 8rpx;
				border: 0;
				font-size: 28rpx;
				color: rgba(0, 0, 0, 0.9);
			}

		}

		.setting-list {
			padding: 32rpx;
			box-sizing: border-box;

			.setting-item {
				display: flex;
				align-items: center;
				padding: 24rpx 38rpx;
				box-sizing: border-box;
				background: #FFFFFF;
				border-radius: 16rpx 16rpx 16rpx 16rpx;
				margin-bottom: 32rpx;

				&:last-child {
					margin-bottom: 0;
				}

				.setting-value {
					height: 40rpx;
					font-size: 24rpx;
					color: rgba(0, 0, 0, 0.6);
					line-height: 40rpx;
					margin-left: auto;
				}

				.setting-label {
					height: 48rpx;
					font-size: 32rpx;
					color: #1D2129;
					line-height: 48rpx;
					margin-left: 20rpx;
				}

				.setting-icon {
					width: 30rpx;
					height: 35rpx;
				}

			}
		}
	}
</style>